% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/cces_std-for-acs.R
\name{ccc_std_demographics}
\alias{ccc_std_demographics}
\title{Recode CCES variables so that they merge to ACS variables}
\usage{
ccc_std_demographics(
  tbl,
  only_demog = FALSE,
  age_key = deframe(ccesMRPprep::age5_key),
  wh_as_hisp = TRUE,
  bh_as_hisp = TRUE
)
}
\arguments{
\item{tbl}{The cumulative common content. It can be any subset but must include variables
\code{age}, \code{race}, \code{educ}, \code{gender}, \code{st}, \code{state},
and \code{cd}. Factor variables must a haven_labelled class variable as is
the output of \code{get_cces_dataverse("cumulative")}. See \link{ccc_samp} for an example.
Any other file (for example, year-specific common contents) are not compatible with
this function.}

\item{only_demog}{Drop variables besides demographics? Defaults to FALSE}

\item{age_key}{The vector key to use to bin age. Can be \code{deframe(age5_key)} or \code{deframe(age10_key)}}

\item{wh_as_hisp}{Should people who identify as both White and Hispanic be
coded as "Hispanic",  thereby leaving all remaining "Whites" as Non-Hispanic Whites
by definition? Could be \code{NULL} if you know the column \code{hispanic} is not in the
data. For more information, see \url{https://bit.ly/3hZ6mz4}.}

\item{bh_as_hisp}{Same as \code{wh_as_hisp} but for Black Hispanics. Defaults to TRUE.}
}
\value{
The output is of the same dimensions as the input (unless \code{only_demog = TRUE})
but with the following exceptions:
\itemize{
\item \code{age} is coded to match up with the ACS bins and the recoding occurs
in a separate function, \code{ccc_bin_age}. The unbinned age is left instead to
\code{age_orig}.
\item \code{educ} is recoded (coarsened and relabelled) to match up with the ACS.
(the original version is left as \code{educ_cces_chr}). Recoding is governed by
the key-value pairs \link{educ_key}
\item the same goes for \code{race}. These recodings are governed by the
key-value pair \link{race_key}.
\item \code{cd} is standardized so that at large districts are given "01" and
single-digit districts are padded with 0s. e.g. \code{"WY-01"} and \code{"CA-02"}.
}
}
\description{
Recode CCES variables so that they merge to ACS variables
}
\section{Input Requirements}{

This function requires data to have the following columns:
\itemize{
\item A string column called \code{st} that is a two-letter abbreviation of the state, or a labelled
variable coercible to a string.
\item A string column called \code{cd} that has the congressional district that is of the form
\code{"WY-01"}, OR a numeric column called \code{dist} that has the numeric district number.
\code{cd_up} can also be used for the district in the upcoming election.
\item A <numeric+labelled> column called \code{educ} for education, \code{race} for race,
\code{age} for age, and \code{gender} for gender, with values following
the cumulative content.
}
}

\examples{

library(dplyr)

 ccc_std_demographics(ccc_samp)
 ccc_std_demographics(ccc_samp, wh_as_hisp = FALSE) \%>\% count(race)
 ccc_std_demographics(ccc_samp, bh_as_hisp = FALSE, wh_as_hisp = FALSE) \%>\% count(race)

\dontrun{
 # For full data (takes a while)
 library(dataverse)
 cumulative_rds <- get_cces_dataverse("cumulative")
 cumulative_std <- ccc_std_demographics(cumulative_rds)
 }

\dontrun{
 wrong_cd_fmt <- mutate(ccc_samp, cd = str_replace_all(cd, "01", "1"))
 wrong_cd_fmt \%>\% filter(st == "HI") \%>\% count(cd)

 # throws error because CD is formatted the wrong way
 ccc_std_demographics(wrong_cd_fmt)
}


}
